package com.zpark;

import java.util.Arrays;
import java.util.Scanner;

public class NastyFrog {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入稻田的行数：");
        int r = scan.nextInt();
        System.out.println("请输入稻田的列数：");
        int c = scan.nextInt();
        System.out.println("请输入被踩踏的稻子数");
        int n = scan.nextInt();
        Plant[] plants = new Plant[n];
        for (int i = 0; i < n; i++){
            plants[i] = new Plant();
            System.out.println("请输入第" + (i + 1) + "颗水稻的x坐标");
            plants[i].setX(scan.nextInt());
            System.out.println("请输入第" + (i + 1) + "颗水稻的y坐标");
            plants[i].setY(scan.nextInt());
        }

        System.out.println("排序前 -> " + Arrays.toString(plants));
        sort(plants);
        System.out.println("排序后 -> " + Arrays.toString(plants));



    }

    private static void sort(Plant[] plants){

        Plant swapPlant;

        for (int i = 0; i < plants.length - 1; i++){
            for (int j = i + 1; j < plants.length; j++){
                if (plants[i].compare(plants[i], plants[j]) > 0){
                    swapPlant = plants[i];
                    plants[i] = plants[j];
                    plants[j] = swapPlant;
                }
            }
        }

    }

}
